package com.education.welco.controller.app;


import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.LResources;
import com.education.welco.service.ILResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 课程资源 信息操作处理
 *
 * @author d
 * @date 2020-05-08
 */

@Api(tags = {"APP-平台课程--实战视频"})
@RestController
@RequestMapping("/app/lResources")
public class AppLResourcesController extends BaseController {

    @Autowired
    private ILResourcesService resourcesService;


    @ApiOperation(value = "平台课程--实战视频和照片接口", httpMethod = "GET")
    @GetMapping("/selectByViedo")
    public ApiReturnObject findByViedo(Integer catalogId, String type) {
        if (catalogId == null || type == null || "".equals(type)) {
            return new ApiReturnObject("201", "参数缺失", "参数缺失");
        } else {
            LResources lResources = new LResources();
            lResources.setRCatalogid(catalogId);
            //1 教学课件  2 技术文档  3 教学笔记 4 图片 5 视频
            lResources.setType(type);
            List<LResources> lResourcesList = resourcesService.selectLResourcesList(lResources);
            return new ApiReturnObject("200", "查询成功", lResourcesList.size(), lResourcesList);
        }
    }

    @ApiOperation(value = "平台课程--教学资料接口", httpMethod = "GET")
    @GetMapping("/selectByData")
    public ApiReturnObject selectByData(Integer catalogId) {
        if (catalogId == null) {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        } else {
            Map<String, Object> map = new HashMap<>();
            //教学课件  courseware
            LResources courseware = new LResources();
            courseware.setRCatalogid(catalogId);
            courseware.setType("1");
            List<LResources> list1 = resourcesService.selectLResourcesList(courseware);
            map.put("jxzl",list1);
            //技术文档  documents
            LResources documents = new LResources();
            documents.setRCatalogid(catalogId);
            documents.setType("2");
            List<LResources> list2 = resourcesService.selectLResourcesList(documents);
            map.put("jswd",list2);

            return new ApiReturnObject("200", "查询成功",map);
        }
    }


    @ApiOperation(value = "平台课程--虚拟教学接口 安卓", httpMethod = "GET")
    @GetMapping("/selectByFlash")
    public ApiReturnObject selectByFlash(Integer catalogId) {
        if (catalogId == null) {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        } else {
            List<List<LResources>> list = new ArrayList<>();

            //3D视频
            LResources lResources3D = new LResources();
            lResources3D.setRCatalogid(catalogId);
            lResources3D.setType("6");
            List<LResources> lise1 = resourcesService.selectLResourcesList(lResources3D);
            list.add(lise1);
            //flash视频
            LResources lResourcesFlash = new LResources();
            lResourcesFlash.setRCatalogid(catalogId);
            lResourcesFlash.setType("7");
            List<LResources> lise2 = resourcesService.selectLResourcesList(lResourcesFlash);
            list.add(lise2);
            return new ApiReturnObject("200", "查询成功",list.size(),list);
        }
    }


    @ApiOperation(value = "平台课程--虚拟教学接口  IOS", httpMethod = "GET")
    @GetMapping("/selectByFlash2IOS")
    public ApiReturnObject selectByFlash2IOS(Integer catalogId) {
        if (catalogId == null) {
            return new ApiReturnObject("201", "catalogId为空", "catalogId为空");
        } else {

            //3D视频
            LResources lResources3D = new LResources();
            lResources3D.setRCatalogid(catalogId);
            lResources3D.setType("6");
            List<LResources> list = resourcesService.selectLResourcesList(lResources3D);
            //flash视频
            LResources lResourcesFlash = new LResources();
            lResourcesFlash.setRCatalogid(catalogId);
            lResourcesFlash.setType("7");
            List<LResources> lise2 = resourcesService.selectLResourcesList(lResourcesFlash);
            //把url设置到flash
            if (lise2.size() != 0) {
                for (LResources lResources : lise2) {
                    lResources.setFlash(lResources.getRUrl());
                }
            }
            //如果没有3D 就直接返回flash
            if (list.size() == 0){
                return new ApiReturnObject("200", "查询成功",lise2.size(),lise2);
            }


            if (lise2.size() != 0 && list.size() != 0) {
                //3D
                for (LResources lResource : list) {
                    //flash
                    for (LResources lResources : lise2) {
                        lResource.setFlash(lResources.getRUrl());
                    }
                }
            }
            return new ApiReturnObject("200", "查询成功",list.size(),list);
        }
    }


}